package com.tripshare.sdk.weixin.api.task;

import com.tripshare.sdk.weixin.api.util.AccessTokenUtil;
import com.tripshare.sdk.weixin.api.WeixinConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 定时刷新access_token
 */
@Slf4j
@Component
public class AccessTokenTask {

    @Autowired
    private WeixinConfig weixinConfig;

    /**
     * 每5分钟加载一次数据
     */
    @Scheduled(fixedRate = (long) (1.5 * 3600 * 1000L))
    public void refreshAccessToken() {
        log.info("start refreshAccessToken");
        AccessTokenUtil.refreshAccessToken(weixinConfig.getAppId(), weixinConfig.getAppSecret());
    }

}
